package cn.codexin.wechatofficial.controller;

import cn.codexin.wechatofficial.model.dbo.*;
import cn.codexin.wechatofficial.service.RealTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ly
 * @date 2020/8/10 0010 13:48
 * 有关实时数据的接口
 */
@RestController
@RequestMapping(value = "realData", produces = "application/json;charset=UTF-8")
public class RealTimeDataController {
    @Autowired
    private RealTimeService realTimeService;

    /*主界面*/
    @GetMapping("/index")
    public Map<String,Object> toIndex(@RequestParam int ModuleID){
        Map<String,Object> map = new HashMap<>();
        try {
            List<MVIndexPojo> mvIndexPojoList = realTimeService.MVIndex(ModuleID);
            List<SPSIndexPojo> spsIndexPojoList = realTimeService.SPSIndex(ModuleID);
            if (mvIndexPojoList.size()==0||spsIndexPojoList.size()==0){
                throw new RuntimeException("该房间还未设置遥测、遥信监测点,请联系管理员！");
            }else {
                map.put("state",true);
                map.put("msg","查询成功");
                map.put("mvPojoList",mvIndexPojoList);
                map.put("spsPojoList",spsIndexPojoList);
            }
        } catch (Exception e) {
            e.printStackTrace();
            map.put("state",false);
            map.put("msg","查询失败,提示："+e.getMessage());
        }
        return map;
    }
    /*设备工况*/
   /* @GetMapping("/equipmentState")
    public Map<String,Object> equipmentState(@RequestParam int ModuleID){
        Map<String,Object> map = new HashMap<>();
        try {
            List<SPSPojo> spsPojoList = realTimeService.SPSRealTimeList(ModuleID);
            if (spsPojoList.size()==0){
                throw new RuntimeException("该房间还未设置遥信监测点,请联系管理员！");
            }else {
                map.put("state",true);
                map.put("msg","查询成功");
                map.put("spsPojoList",spsPojoList);
            }
        } catch (Exception e) {
            e.printStackTrace();
            map.put("state",false);
            map.put("msg","查询失败,提示："+e.getMessage());
        }
        return map;
    }*/
   /*设备工况*/
    @GetMapping("/equipmentState")
    public Map<String,Object> equipmentState(@RequestParam int ModuleID){
        Map<String,Object> map = new HashMap<>();
        try {
            List<MVPojo> mvPojoList = realTimeService.MVRealTimeList(ModuleID);
            List<SPSIndexPojo> spsPojoList = realTimeService.SPSIndex(ModuleID);
            if (mvPojoList.size()==0||spsPojoList.size()==0){
                throw new RuntimeException("该房间还未设置遥测、遥信监测点,请联系管理员！");
            }else {
                map.put("state",true);
                map.put("msg","查询成功");
                map.put("mvPojoList",mvPojoList);
                map.put("spsPojoList",spsPojoList);
            }
        } catch (Exception e) {
            e.printStackTrace();
            map.put("state",false);
            map.put("msg","查询失败,提示："+e.getMessage());
        }
        return map;
    }
    /*实时告警*/
    @GetMapping("/currentWarning")
    public Map<String,Object> currentWarning(@RequestParam int ModuleID){
        Map<String,Object> map = new HashMap<>();
        try {
            List<SPSAlarm> spsAlarmList = realTimeService.SPSAlarm(ModuleID);
            List<MVIndexPojo> mvAlarmList = realTimeService.MVAlarm(ModuleID);
            if (spsAlarmList.size()==0&&mvAlarmList.size()==0){
                throw new RuntimeException("该房间还未设置监测点,请联系管理员！");
            }else {
                map.put("state",true);
                map.put("msg","查询成功");
                map.put("spsAlarmDefList",spsAlarmList);
                map.put("mvAlarmDefList",mvAlarmList);
            }
        } catch (Exception e) {
            e.printStackTrace();
            map.put("state",false);
            map.put("msg","查询失败,提示："+e.getMessage());
        }
        return map;
    }
}
